<template>
	<view class="container">
		<view class="top-bg">
			<u-navbar 
			isBack 
			title="查看详情" 
			background="rgba(0,0,0,0)"
			back-icon-color="#fff"
			title-color="#fff"></u-navbar>
			<view class="title">
				<text class="iconfont icon-shijianxuanzhong"></text>
				<text class="pay">待确定</text>
			</view>
			<view class="time">
				<!-- 还剩 {{countdown}} 自动关闭订单 -->
			</view>
		</view>
		<view class="content">
			<view class="detail">
				<view class="detail-content">
					<view class="product df-bt">
						<view class="product-info df-ct">
							<image :src="list.headimg.path" mode="" class="product-img"></image>
							<view class="name">
								<view class="name-top">{{list.realname}}</view>
								<view class="phone">{{list.phone}}</view>
							</view>
						</view>
						<view class="iconfont icon-dadianhua" @click="toTelPhone"></view>						
					</view>
					<view class="top">
						<view class="size df-bt">
							<view class="">
								<view class="t">户型</view>
								<view>{{list.house_type}}</view>
							</view>
							<view class="">
								<view class="t">面积</view>
								<view>{{list.house_area}}m²</view>
							</view>
							<view class="right">
								<view class="t">小区</view>
								<view>{{list.estate}}</view>
							</view>
						</view>
						<view class="address">
							<view class="address-title t">
								装修地址
							</view>
							<view class="address-detail">
								{{list.address}}
							</view>
						</view>						
					</view>
				</view>				
			</view>
			<view class="contract">
				<view class="title">
					订单合同
				</view>
				<view class="upload" v-if="Array.isArray(list.contract_thumb_url)">
					<view class="imgBox" v-for="(item,index) in list.contract_thumb_url" :key="index">
						<image :src="item.path" mode="" @click="toViewImg(index,1)"></image>
						<!-- <image :src="`${baseimg}/static/constr/remove.png`" @click="removeImg(index)" mode=""></image> -->
					</view>
					<!-- <view class="uploadBtn" @click="uploadFN(1)">+<span>图片/PDF</span></view> -->
				    <!-- <u-upload ref="" :on-change="handleChange" :auto-upload="false" upload-text="图片/PDF"></u-upload> -->
				</view>
				<view class="upload" v-else>
					<view class="imgBox">
						<image :src="list.contract_thumb_url.path" @click="toViewImg(0,1)" mode=""></image>
					</view>
				</view>
			</view>	
			<view class="contract">
				<view class="title">
					设计图纸
				</view>
				<view class="upload" v-if="Array.isArray(list.draw_thumb_url)">
					<view class="imgBox" v-for="(item,index) in list.draw_thumb_url" :key="index">
						<image :src="item.path" mode="" @click="toViewImg(index,2)"></image>
						<!-- <image :src="`${baseimg}/static/constr/remove.png`" @click="constrImgDel(index)" mode=""></image> -->
					</view>
					<!-- <view class="uploadBtn" @click="uploadFN(2)">+<span>添加图纸</span></view> -->
				    <!-- <u-upload ref="" :on-change="handleChange" :auto-upload="false" upload-text="图片/PDF"></u-upload> -->
				</view>
				<view class="upload" v-else>
					<view class="imgBox">
						<image :src="list.draw_thumb_url.path" @click="toViewImg(0,2)" mode=""></image>
					</view>
				</view>
			</view>	
			<view class="contract">
				<view class="title">
					选材单
				</view>
				<view class="upload" v-if="Array.isArray(list.material_thumb_url)">
					<view class="imgBox" v-for="(item,index) in list.material_thumb_url" :key="index">
						<image :src="item.path" mode="" @click="toViewImg(index,3)"></image>
						<!-- <image :src="`${baseimg}/static/constr/remove.png`" @click="constrImgDel(index)" mode=""></image> -->
					</view>
					<!-- <view class="uploadBtn" @click="uploadFN(2)">+<span>添加图纸</span></view> -->
				    <!-- <u-upload ref="" :on-change="handleChange" :auto-upload="false" upload-text="图片/PDF"></u-upload> -->
				</view>
				<view class="upload" v-else>
					<view class="imgBox">
						<image :src="list.material_thumb_url.path" @click="toViewImg(0,3)" mode=""></image>
					</view>
				</view>
			</view>	
			<view class="message">
				<view class="title">
					订单信息
				</view>
				<view class="appeal">
					<text class="left">客户诉求</text>
					<text class="right-appeal">{{list.remark}}</text>
				</view>
				<view class="number df">
					<text class="left">订单编号</text>
					<text class="center">{{list.order_no}}</text>
					<text class="copy" @click="copyBtn">复制</text>
					
				</view>
				<view class="time df">
					<text class="left">下单时间</text>
					<text class="right">{{list.create_time | dateformat("YYYY-MM-DD HH:mm:ss")}}</text>
				</view>
			</view>
			<view class="message">
				<view class="title">
					支付信息
				</view>
				<view class="money df">
					<text class="left">合同金额</text>
					<text class="total-money">¥ {{list.contract_price}}</text>
				</view>
				<view class="appeal">
					<text class="left">支付次数</text>
					<text class="right-appeal">{{list.pay_progress.length}}</text>
				</view>
				<view class="time df">
					<text class="left">支付比例</text>
					<text class="right">{{list.pay_rule?list.pay_rule.replace(/,/g,'、'):''}}</text>
				</view>
				<!-- 支付比例 -->
				<view class="payNumList">
					<view class="item" v-for="(item,index) in list.pay_progress" :key="index">
						<view class="info">
							<view class="num">{{index+1}}</view>
							{{item.rate*100}}%
							<text>(￥{{item.amount}})</text>
						</view>
						<view v-if="item.checked || item.pay_status!=0" class="btn" @click="toCollect(item.id,item.pay_status)" :class="{'active':item.checked&&item.pay_status==0}">{{item.pay_status==0?'发起收款':item.pay_status==1?'待付款':'已付款'}}</view>
					</view>
				</view>
				<!-- 备注 -->
				<view class="remarksBox">
					<view class="title">
						备注
					</view>
					<view class="textarea">
						 <textarea disabled v-model="list.pay_rule_desc" maxlength="1000" placeholder-style="color:#D8D8D8" placeholder="备注信息~"/>
					</view>
				</view>
			</view>
		</view>
		<view class="footer">
			<button type="default" class="btn-text" @click="toCancelOrder">取消订单</button>
			<button type="default" class="btn-text" @click="toEdit">修改信息</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseimg:this.$static,
				list:{},
				id:null, // 订单iddata() {
				h:23,//时
				m:59,//分
				s:59,//秒
				countdown:'24:00:00',//倒计时
				timer:null,//定时器
			}
		},
		onLoad(option) {
			this.id = option.id
			this.getDetail()
			this.timer = setInterval(()=>{
			   this.timeCount()
			   if(this.h<=0&&this.m<=0&&this.s<=0){
				   clearInterval(this.timer)
				   this.timer = null
				   this.countdown = '00:00:00'
				  //  this.$api.designerOrder_cancel({id:this.id}).then(res=>{
				  //  	if(res.code==1){
						// uni.showToast({
						// 	title:'订单已过期,即将自动关闭!',
						// 	icon:'none'
						// })
				  //  		setTimeout(function(){
						// 	uni.navigateBack({
						// 		delta:1
						// 	})
						// },2000)
				  //  	}
				  //  })
			   }
			},1000)
		},
		onUnload() {
			clearInterval(this.timer)
			this.timer = null
		},
		onShow() {
			this.getDetail()
		},
		methods:{
			handleFile(event){
				console.log(event,"照片信息")
			},
			// 获取订单详情
			getDetail(){
				let params = {
					id:this.id
				}
				this.$api.designerOrder_getDetail(params).then(res=>{
					if(res.code == 1){
						this.list = res.data
						
						let time = res.data.handle_time*1000
						let time_2 =(time+24*60*60*1000)-60*1000
						console.log(time,'1111')
						console.log(time_2,'2222')
						let needTime = this.$utils.getFutreTime(time_2)
						console.log(needTime,'需要的时间')
						let splitTime = needTime.split(':')
						console.log(splitTime,'还需多久')
						this.h = Number(splitTime[0])
						this.m = Number(splitTime[1]) 
						this.s = Number(splitTime[2]) 
						
						// 处理数据按顺序进行收款
						this.list.pay_progress.map((item,index)=>{
							item.checked = false
							if(this.list.pay_progress[0].pay_status==0){
								this.list.pay_progress[0].checked = true
							}else if(index!=0 && this.list.pay_progress[index-1].pay_status!=0 && this.list.pay_progress[index].pay_status==0){
								this.list.pay_progress[index].checked = true
							}
						})
					}
				})
			},
			
			// 倒计时时间
			timeCount(){
				--this.s;
				if(this.s<0){
					--this.m;
					this.s=59;
				}
				if(this.m<0){
					--this.h;
					this.m=59
				}
				if(this.h<0){
					this.s=0;
					this.m=0;
				}
				let h = ''
				let m = ''
				let s = ''
				h = this.h>9?this.h:'0'+this.h
				m = this.m>9?this.m:'0'+this.m
				s = this.s>9?this.s:'0'+this.s
				this.countdown = h+":"+m+":"+s
			},
			// 联系打电话
			toTelPhone(){
				console.log(this.list.phone,'电话电话')
				uni.makePhoneCall({
				 	// 手机号
				    phoneNumber: this.list.phone, 
					// 成功回调
					success: (res) => {
						console.log('调用成功!')	
					},
					// 失败回调
					fail: (res) => {
						console.log('调用失败!')
					}
				});
			},
			
			// 复制按钮
			copyBtn(){
				uni.setClipboardData({
				    data: this.list.order_no,
				    success: function () {
						console.log('复制成功')
				    }
				});
			},
			// 图片预览
			toViewImg(index,type) { //type=1合同，type=2施工图纸，type=3选材单
				let imgArr = type==1?this.list.contract_thumb_url:type==2?this.list.draw_thumb_url:this.list.material_thumb_url;
				let urlType = Array.isArray(imgArr)
				console.log(imgArr,'需要预览的图片')
				let imgUrl = []
				if (urlType) {
					imgArr.map(item => {
						imgUrl.push(item.path)
					})
				} else {
					imgUrl.push(imgArr.path)
				}
				uni.previewImage({
					current: index, //预览图片的下标
					urls: imgUrl //预览图片的地址，必须要数组形式，如果不是数组形式就转换成数组形式就可以
				});
			},
			
			// 发起收款按钮
			toCollect(id,status){
				if(status==0){
					this.$api.toCollection({id}).then(res=>{
						console.log(res,'发起收款')
						if(res.code==1){
							uni.showToast({
								title:'发起收款成功',
								icon:'success'
							})
							this.getDetail()
						}else{
							uni.showToast({
								title:res.msg,
								icon:'none'
							})
						}
					})
				}
			},
			
			// 取消订单
			toCancelOrder(){
				uni.showModal({
					content:'确定取消此订单吗？',
					success:res=>{
						if(res.confirm){
							this.$api.designerOrder_cancel({id:this.id}).then(res=>{
								if(res.code==1){
									uni.showToast({
										title:'取消成功',
										icon:'success '
									})
									setTimeout(function(){
										uni.navigateBack({
											delta:1
										})
									},500)
								}
							})
						}
					}
				})
			},
			// 修改信息按钮
			toEdit(){
				uni.navigateTo({
					url:`dispose?id=${this.id}&edit=1`
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	.container{
		.top-bg{
			background:  url(https://manager.ryz1620.com/static/home-personal/personal-bg.png) no-repeat top;
			width: 100%;
			height: 468rpx;
			position: relative;
			/deep/ .u-navbar .u-border-bottom{
						border: 0 !important;
			}
			.title{
				display: flex;
				margin: 80rpx 0 0 44rpx;
				.icon-shijianxuanzhong{
					width: 40rpx;
					height: 40rpx;
					color: #94e3b4;
					margin-right: 6rpx;
				}
				.pay{
					font-size: 36rpx;
					font-family: PingFang SC;
					font-weight: 500;
					line-height: 36rpx;
					color: #FFFFFF;
				}
			}
			.time{
				font-size: 22rpx;
				font-family: PingFang SC;
				font-weight: 400;
				line-height: 36rpx;
				color: #FFFFFF;
				margin: 6rpx 0 0 44rpx;
			}
		}
		.content{
			position: absolute;
			left: 0;
			top: 350rpx;
			z-index: 99;
			padding: 24rpx 24rpx 0rpx 24rpx;
			padding-bottom: constant(safe-area-inset-bottom);
			padding-bottom: env(safe-area-inset-bottom);
			margin-bottom: 150rpx;
			width: 100%;
			.detail{
				// padding: 0 24rpx;
				
				.detail-content{
					background-color: #fff;
					padding: 30rpx 24rpx;
					margin-bottom: 22rpx;
					border-radius: 16rpx;
					.top{
						padding: 28rpx;
						background: #F8F8F8;
						border-radius: 8rpx;
						color: #505050;
						margin-bottom: 30rpx;
						.size{
							margin-bottom: 40rpx;
							.right{
								display: flex;
								flex-direction: column;
								justify-content: flex-end;
								text-align: right;
								// align-items: right;
								}
						}
						.address{
							
							.address-detail{
								font-size: 26rpx;
								font-family: PingFang SC;
								font-weight: 400;
								line-height: 40rpx;
								color: #505050;
							}
						}
							.t {
								font-size: 22rpx;
								font-family: PingFang SC;
								font-weight: 400;
								line-height: 36rpx;
								color: #A0A0A0;
							}
							
						
						
					}
					.product {
						padding-bottom: 30rpx;
						// padding-top: 22rpx;
						.product-img {
							width: 84rpx;
							height: 84rpx;
							border-radius: 50%;
							margin-right: 20rpx;
						}
						.name{
							.name-top{
								font-size: 26rpx;
								font-weight: 500;
								line-height: 40rpx;
								color: #0A0605;
							}
							.phone{
								font-size: 26rpx;
								font-weight: 400;
								line-height: 40rpx;
								color: #505050;
							}
						}
						
						.iconfont{font-size: 50rpx;}
					}
					
					.btn-box {
						&:after { display: block; clear: both; content: ''; visibility: hidden; height: 0; }
						.more {
							float: left;
							font-size: 26rpx;
							font-family: PingFang SC;
							font-weight: 400;
							line-height: 40rpx;
							color: #A0A0A0;
							padding-top: 10rpx;
						}
						.price-box {
							text-align: right;
							padding: 40rpx 0 22rpx 0;
							font-size: 26rpx;
							font-family: PingFang SC;
							font-weight: 500;
							line-height: 20rpx;
							color: #878787;
							.d-price {
								color: #dfb368;
								font-size: 32rpx;
								padding-left: 20rpx;
							}
						}
						.btn {
							// width: 50%;
							// float: right;
							display: flex;
							justify-content:flex-end ;
							align-items: center;
							.btn-text {
								width: 172rpx;
								height: 64rpx;
								background: #FFFFFF;
								border: 2rpx solid #505050;
								opacity: 1;
								border-radius: 32rpx;
								text-align: center;
								line-height: 64rpx;
								color: #505050;
								font-size: 26rpx;
								margin: 0 10rpx;
							}
							.active{
								background-color: #DBA954;
								color: #fff;
								border: 0;
							}
						}
						
					}
				}
			}
			.contract{
				padding: 24rpx;
				background-color: #fff;
				border-radius: 16rpx;
				margin-top: 30rpx;
				.title{
					font-size: 30rpx;
					font-family: PingFang SC;
					font-weight: 500;
					line-height: 40rpx;
					color: #0A0605;
				}
				
				.upload{
					margin-top: 40rpx;
					display: flex;
					align-items: center;
					flex-wrap: wrap;
					.imgBox{
						margin: 0 5rpx 10rpx;
						position: relative;
						width: 200rpx;
						height: 200rpx;
						border-radius: 4rpx;
						image:nth-child(1){
							width: 100%;
							height: 100%;
							border-radius: 4rpx;
						}
						image:nth-child(2){
							width: 50rpx;
							height: 50rpx;
							position: absolute;
							top: 5rpx;
							right: 5rpx;
						}
					}
					.uploadBtn{
						margin: 0 5rpx 10rpx;
						background-color: #F8F8F8;
						border-radius: 4rpx;
						width: 200rpx;
						height: 200rpx;
						font-size: 60rpx;
						display:  flex;
						align-items: center;
						color: #A0A0A0;
						flex-direction: column;
						justify-content: center;
						span{font: 400 22rpx/36rpx PingFang SC;}
					}
				}
			}
			.message{
				padding: 24rpx;
				background-color: #fff;
				border-radius: 16rpx;
				margin-top: 30rpx;
				.title{
					font-size: 30rpx;
					font-family: PingFang SC;
					font-weight: 500;
					line-height: 40rpx;
					color: #0A0605;
				}
				.left{
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 400;
					line-height: 40rpx;
					color: #A0A0A0;
					display: inline-block;
					// margin-right: 10rpx;
					width: 27%;
				}
				.right{
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 400;
					line-height: 40rpx;
					color: #505050;
				}
				.copy{
					padding: 6rpx 18rpx;
					background-color: rgba(219, 169, 84, 0.1);
					font-size: 18rpx;
					font-family: PingFang SC;
					font-weight: 400;
					line-height: 20rpx;
					color: #DBA954;
					border-radius: 18rpx;
					margin-left: 10rpx;
				}
				.total-money{
					color: #DBA954;
				}
				
				.right-appeal{
					width: 73%;
					// margin-left: 62rpx;
				}
				.df{
					// display: inline-flex;
					margin: 20rpx 0;
				}
				// 支付比例列表
				.payNumList{
					.item{
						display: flex;
						justify-content: space-between;
						align-items: center;
						margin: 30rpx 0;
						.info{
							display: flex;
							align-items: center;
							.num{
								width: 30rpx;
								height: 30rpx;
								border: 2rpx solid #A0A0A0;
								border-radius: 50%;
								text-align: center;
								font-size: 22rpx;
								line-height: 30rpx;
								margin-right: 20rpx;
							}
							text{
								color: #DCAB58;
								margin-left: 20rpx;
							}
						}
						.btn{
							color: #DCAB58;
						}
						.active{
							padding: 8rpx 30rpx;
							border-radius: 28rpx;
							color: #fff;
							background: linear-gradient(90deg, #DBA954 0%, #EABA6A 100%);
						}
					}
				}
				// 备注
				.remarksBox{
					// padding: 24rpx;
					background-color: #fff;
					border-radius: 16rpx;
					margin-top: 30rpx;
					.title{
						font-size: 30rpx;
						font-family: PingFang SC;
						font-weight: 500;
						line-height: 40rpx;
						color: #0A0605;
					}
					.textarea{
						background: #F8F8F8;
						padding: 24rpx;
						height: 160rpx;
						overflow-y: auto;
						margin-top: 20rpx;
					}
				}
			}
		}
		.footer{
			height: 120rpx;
			width: 100%;
			background-color: #fff;
			position: fixed;
			left: 0;
			bottom: 0;
			z-index: 99;
			padding:0 30rpx;
			display: flex;
			justify-content:flex-end ;
			align-items: center;
			height: calc(120rpx+ constant(safe-area-inset-bottom)); 			height: calc(120rpx + env(safe-area-inset-bottom));			padding-bottom: constant(safe-area-inset-bottom);			padding-bottom: env(safe-area-inset-bottom);
			.btn-text {
				width: 172rpx;
				height: 64rpx;
				background: #FFFFFF;
				border: 2rpx solid #505050;
				opacity: 1;
				border-radius: 32rpx;
				text-align: center;
				line-height: 64rpx;
				color: #505050;
				font-size: 26rpx;
				margin: 0 10rpx;
			}
			.active{
				background-color: #DBA954;
				color: #fff;
				border: 0;
				width: 240rpx;
			}
		}
	}
</style>

